package com.kygl.admin.service;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.kygl.admin.util.AdminUtil;
//import com.lerx.site.dao.ISiteInfoDao;
import com.opensymphony.xwork2.ActionSupport;

public class AdminSafetyCertification extends ActionSupport implements
		ServletRequestAware {

	private HttpServletRequest request;
	//private ISiteInfoDao siteInfDaoImp;
//	public void setSiteInfDaoImp(ISiteInfoDao siteInfDaoImp) {
//		this.siteInfDaoImp = siteInfDaoImp;
//	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String execute() throws Exception {
		//siteInfDaoImp.query();
		// boolean con=true;
		// String safeIp=getText("lerx.administratorSafeIP");
		// if (safeIp!=null && !safeIp.trim().equals("") &&
		// !safeIp.trim().equals("all") &&
		// !safeIp.trim().equals("lerx.administratorSafeIP") &&
		// !IpUtil.isInRange(IpUtil.getRealRemotIP(request).trim(),
		// safeIp)){
		// con=false;
		// }
		// String safeAdminSessionStr = getText(
		// "lerx.sessionPrefixOfAdminAuthentication").trim();
		// safeAdminSessionStr=safeAdminSessionStr.replace("servername",
		// request.getServerName());
		//
		// if (ActionContext.getContext().getSession().get(safeAdminSessionStr)
		// == null
		// || !ServletActionContext.getContext().getSession()
		// .get(safeAdminSessionStr).equals("passed") || !con) {
		// ActionContext.getContext().getSession().put("LerxAdmin", "false");
		// //ServletActionContext.getRequest().setAttribute("LerxAdmin",
		// "false");
		// return LOGIN;
		//
		// }else{
		// ActionContext.getContext().getSession().put("LerxAdmin", "true");
		// return SUCCESS;
		// }
		if (checkAdmin()) {
			request.getSession().setAttribute("KyglAdmin", "true");
			return SUCCESS;
		} else {
			request.getSession().setAttribute("KyglAdmin", "false");
			return LOGIN;
		}

	}

	private boolean checkAdmin() {
		return AdminUtil
				.checkAdmin(this, getText("kygl.host.current"), request);
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		// TODO Auto-generated method stub

	}

}
